package ferp.core.calc.scorer;

import ferp.core.calc.Calculator;
import ferp.core.game.Game;
import ferp.core.game.Settings;

/**
 * User: olegs
 * Date: 12/3/13 1:51 PM
 */
public class Misere extends Scorer
{
  public static final Misere instance = new Misere();

  @Override
  protected void update(Game g, Settings settings, Calculator c)
  {
    if (g.getDeclarerTricks() == 0)
      // in case the declarer took no tricks write into his pool
      c.writeToPool(g, settings, g.declarer(), c.getPlayCostSuccess(Game.MAXIMUM_TRICKS));
    else
      // otherwise punish for every trick he took
      c.writeToMountain(g, g.declarer(), c.getPlayCostFailure(Game.MAXIMUM_TRICKS) * g.getDeclarerTricks());
  }

  @Override
  protected void statistics(Game g)
  {
    g.statistics.misere[g.player.declarer].sets++;

    if (g.getDeclarerTricks() == 0)
      g.statistics.misere[g.player.declarer].success++;
    else
      g.statistics.misere[g.player.declarer].tricks += g.getDeclarerTricks();
  }
}
